<?php
/** .-------------------------------------------------------------------
* |    Author: 熊伟洋 <chelious@foxmail.com>
* |    WeChat: hello_McGrady
* |    	   QQ: 434493420
* |     Motto: Hungry & Humble
* |---------------------------------------------------------------------
* |    Copyright (c) 2012-2020, www.chelious.com. All Rights Reserved.
* '-------------------------------------------------------------------*/

namespace system\model;

use hdphp\Model\Model;

class Link extends Model{
	//数据表
	protected $table = "link";

	//允许填充字段
	protected $allowFill = [ ];

	//禁止填充字段
	protected $denyFill = [ ];

	//完整表名
	protected $full = false;

	//自动验证
	protected $validate=[
		//['字段名','验证方法','提示信息',验证条件,验证时间]
        ['lname','required','链接名称不能为空',3,3],
        ['url','required','链接地址不能为空',3,3],
        ['sort','required','排序不能为空',3,3],
        ['logo','required','Logo图不能为空',3,3],
        ['url','http','链接地址不符合规则',3,3],
	];

	//自动完成
	protected $auto=[
		//['字段名','处理方法','方法类型',验证条件,验证时机]
        ['addtime','time','function',3,1],
	];

	//自动过滤
    protected $filter=[
        //[表单字段名,过滤条件,处理时间]
    ];

	//时间操作,需要表中存在created_at,updated_at字段
	protected $timestamps=false;

	//添加链接
    public function add(){
//        p($_POST);
        $link = new Link();
        $link['lname'] = Q('post.lname');
        $link['url'] = Q('post.url');
        $link['sort'] = Q('post.sort');
        $link['logo'] = Q('post.thumb');
        $link->save();
        return true;
    }

    //修改链接
    public function edit(){
        $lid = Q('get.lid');
//        p($_POST);
        $linkData =Link::find($lid);
        $linkData['lname'] = Q('post.lname');
        $linkData['url'] = Q('post.url');
        $linkData['sort'] = Q('post.sort');
        $linkData['logo'] = Q('post.thumb');
        $linkData->save();
        return true;
    }

}